/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package com.fzhucc.modules.sciPersonnelInfo.controller;

import com.fzhucc.annotation.Log;
import com.fzhucc.annotation.rest.AnonymousPostMapping;
import com.fzhucc.modules.requirement.domain.dto.RequirementBoxSeekDto;
import com.fzhucc.modules.sciPersonnelInfo.domain.SciPersonnelInfoMsgBox;
import com.fzhucc.modules.sciPersonnelInfo.domain.dto.SciPersonnelInfoBoxSeekDto;
import com.fzhucc.modules.sciPersonnelInfo.service.SciPersonnelInfoMsgBoxService;
import com.fzhucc.modules.sciPersonnelInfo.domain.dto.SciPersonnelInfoMsgBoxQueryCriteria;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
 * @author yyg
 * @date 2023-12-14
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "劳模:留言箱")
@RequestMapping("/api/sciPersonnelInfoMsgBox")
public class SciPersonnelInfoMsgBoxController {

    private final SciPersonnelInfoMsgBoxService sciPersonnelInfoMsgBoxService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('sciPersonnelInfoMsgBox:list')")
    public void exportSciPersonnelInfoMsgBox(HttpServletResponse response, SciPersonnelInfoMsgBoxQueryCriteria criteria) throws IOException {
        sciPersonnelInfoMsgBoxService.download(sciPersonnelInfoMsgBoxService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询大赛“劳模工匠助企行”人才信息表留言箱")
    @ApiOperation("查询大赛“劳模工匠助企行”人才信息表留言箱")
    @PreAuthorize("@el.check('sciPersonnelInfoMsgBox:list')")
    public ResponseEntity<Object> querySciPersonnelInfoMsgBox(SciPersonnelInfoMsgBoxQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(sciPersonnelInfoMsgBoxService.queryAll(criteria,pageable), HttpStatus.OK);
    }

    @Log("助企行劳模工匠咨询")
    @ApiOperation("助企行劳模工匠咨询")
    @AnonymousPostMapping(value = "/seek")
    public ResponseEntity<Object> seek(@Validated @RequestBody SciPersonnelInfoBoxSeekDto dto) {
        return new ResponseEntity<>(sciPersonnelInfoMsgBoxService.seek(dto), HttpStatus.OK);
    }

    @DeleteMapping
    @Log("删除大赛“劳模工匠助企行”人才信息表留言箱")
    @ApiOperation("删除大赛“劳模工匠助企行”人才信息表留言箱")
    @PreAuthorize("@el.check('sciPersonnelInfoMsgBox:del')")
    public ResponseEntity<Object> deleteSciPersonnelInfoMsgBox(@RequestBody Integer[] ids) {
        sciPersonnelInfoMsgBoxService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}